package com.spzx.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.mapper.CategoryBrandMapper;
import com.spzx.product.mapper.ProductSpecMapper;
import com.spzx.product.service.CategoryService;
import com.spzx.product.service.ProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品规格Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-09
 */
@Service
public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, ProductSpec> implements ProductSpecService {

    @Autowired
    private ProductSpecMapper productSpecMapper;

    private CategoryService categoryService;
    /**
     * 查询商品规格列表
     *
     * @param productSpec 商品规格
     * @return 商品规格
     */
    @Override
    public List<ProductSpec> selectProductSpecList(ProductSpec productSpec) {
        return productSpecMapper.selectProductSpecList(productSpec);
    }

    @Override
    public ProductSpec selectProductSpecById(Long id) {
        //根据商品规格id查询信息
        ProductSpec productSpec = baseMapper.selectById(id);
        //商品规格所属所有层分类的Id查询出来
        Long categoryId = productSpec.getCategoryId();//第三层分类ID
        //根据第三册id找到第二第一层
        categoryService.getAllCategoryById(categoryId);
        return productSpec;
    }

    @Override
    public List<ProductSpec> selectProductSpecListByCategoryId(Long categoryId) {
        LambdaQueryWrapper<ProductSpec> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductSpec::getCategoryId,categoryId);
        List<ProductSpec> list = baseMapper.selectList(wrapper);
        return list;
    }

}